package com.credit.dao.teacher;/**
 * @Classname UserDAO
 * @Description 教师信息DAO接口
 * @Date 2020/10/4 16:42
 * @Created by SHTL
 */

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @InterfaceName UserDAO
 * @Description TODO
 */
public interface TeacherUserDAO extends JpaRepository<TeacherUser, Integer>,
        JpaSpecificationExecutor<TeacherUser> {
    TeacherUser findByZhanghu(Integer zhanghu);

    // 根据账号、邮箱、密保进行查找账户
    TeacherUser findByZhanghuAndEmailAndMibao(Integer zhanghu, String email, String mibao);


    TeacherUser getByZhanghuAndPassword(Integer zhanghu, String password);

    TeacherUser findByZhanghuAndEmail(Integer zhanghu, String email);


    // 教师管理页面   获取学院名称
    @Modifying
    @Query(value = "select college from teacher_table GROUP BY college", nativeQuery = true)
    List<Object> getByCollegegroupJjs();

    // 教师管理页面    获取专业名称
    @Modifying
    @Query(value = "select major from teacher_table GROUP BY major", nativeQuery = true)
    List<Object> getByMajorgroupjs();


    // 根据账户信息删除指定的教师账号
    @Modifying
    @Transactional
    @Query(value = "delete from teacher_table as a where a.zhanghu=:zhanghu", nativeQuery = true)
    Integer deleteByZhanghu(@Param("zhanghu") Integer zhanghu);

}
